package com.example.stars_project_android.adapter;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;
import androidx.viewpager2.adapter.FragmentStateAdapter;

import com.example.stars_project_android.fragment.HomeFragment;
import com.example.stars_project_android.fragment.HomePageFragment;

import java.util.ArrayList;
import java.util.List;

/**
 * 首页顶部导航栏适配器
 */
public class MyAdapter extends FragmentStateAdapter {
//    private List<Fragment> fragments;
//
//    public MyAdapter(List<Fragment> fragments, @NonNull FragmentActivity fragmentActivity) {
//        super(fragmentActivity);
//        this.fragments= fragments;
//    }
//
//    @NonNull
//    @Override
//    public Fragment createFragment(int position) {
//        return fragments.get(position);
//    }
//
//    @Override
//    public int getItemCount() {
//        return fragments.size();
//    }

    private List<String> mData = new ArrayList<>();

    public MyAdapter(@NonNull FragmentActivity fragmentActivity, List<String> data) {
        super(fragmentActivity);
        mData = data;
    }

    @NonNull
    @Override
    public Fragment createFragment(int position) {
        return HomePageFragment.newInstance(mData.get(position));
    }

    @Override
    public int getItemCount() {
        return mData.size();
    }
}
